package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.Attendance;
import cn.wolfcode.crm.service.IAttendanceService;
import cn.wolfcode.crm.util.JsonResult;
import cn.wolfcode.crm.util.UserContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class IndexController {
    @Autowired
    IAttendanceService attendanceService;

    @RequestMapping("/index")
    public String index(Model model) {

        return "index";
    }

    @RequestMapping("/welcome")
    public String welcome(Model model) {


        return "other/welcome";
    }

    @RequestMapping("/login")
    public String login(Model model) {

        return "forward:/login.jsp";
    }

    @RequestMapping("/check")
    @ResponseBody
    public Object check() {
        //检查当前登录的用户是否存在于数据库当中,如果存在则把签到按钮设置为禁止
        Attendance attendance = attendanceService.selectByUsername(UserContext.getCurrentUser().getUsername());
        if (attendance != null) {
            return new JsonResult().mark("操作失败");
        }
        return new JsonResult();
    }



}
